﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using OnlineJobPortal.Models;
using System.Data.Entity;
using System.Data;

namespace OnlineJobPortal.Models
{
    public class JobRepository : IJobRepository
    {
        JobPortalEntities7 entityObj = new JobPortalEntities7();

        public List<Job> Jobslist()
        {
            var JobsList = entityObj.Jobs.ToList();
            return JobsList;
        }
        public void SaveJob(Job job)
        {
            var jobdata = entityObj.Jobs;
            jobdata.Add(job);
            entityObj.SaveChanges();
        }
        public Job Find_Job_id(int id)
        {
            Job job = entityObj.Jobs.Find(id);
            return job;
        }

        public List<Job> SearchByID(int id)
        {
            var jobObject = from j in entityObj.Jobs
                            where j.CompanyID == id
                            select j;
            var list = jobObject.ToList();
            return list;
            
        }
        public void UpdateJob(Job job)
        {
            var jobdata = entityObj.Jobs;
            entityObj.Entry(job).State = EntityState.Modified;
            entityObj.SaveChanges();
        }

        public void DeleteJob(int id)
        {
            var jobdata = entityObj.Jobs;
            Job job = jobdata.Find(id);
            jobdata.Remove(job);
            entityObj.SaveChanges();
        }

    }
}